package com.cscj.android.repository.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Upsert
import com.cscj.android.repository.db.entity.UserAgentEntity
import kotlinx.coroutines.flow.Flow


@Dao
interface UserAgentDao {

    @Upsert
    suspend fun upsertUserAgent(userAgentEntity: UserAgentEntity)

    @Upsert
    suspend fun batchInsert(userAgentList: List<UserAgentEntity>)

    @Query("update user_agent set preferred = :preferred")
    suspend fun updatePreferred(preferred: Boolean)

    @Query("update user_agent set preferred = :preferred where id = :id")
    suspend fun updatePreferredById(id: Int, preferred: Boolean)

    @Query("select * from user_agent order by id asc")
    fun userAgentList(): Flow<List<UserAgentEntity>>

    @Query("select * from user_agent where preferred = 1 limit 1")
    fun currentUserAgent(): Flow<UserAgentEntity?>
}